<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>コントロールパネル</title>
    
        <link href="./assets/styles/default.css" rel="stylesheet" />
	<script src="./assets/scripts/libs/jquery-1.7.1.min.js" type="text/javascript"></script>
	<script src="./assets/scripts/import.js" type="text/javascript"></script>
	<script type="text/javascript">
		var del_row = function(){
			$('.delete_category').unbind();
			$('.delete_category').click(function(){	
				var f = function(){
					thisthis.parent().parent().hide();//表示を消す
                                        thisthis.parent().parent().children().children('input[type=text]').val('');//input textを空にする
					$('#table_category tbody tr').each(function(i){
						$('input[type=text]',this).attr("name",'forms[banner][' + (i) + ']');
						$('input[type=radio]',this).attr("name",'forms[status][' + (i) + ']');
						$('input[type=hidden]',this).attr("name",'forms[array_id][' + (i) + ']');
					});
				}
			
				var thisthis = $(this);	
				var v = $('input[type=text]',$(this).closest('tr')).val();
				if(v != ""){					
					customConfirm('削除しますか？',"",$(this),function(){
						f();
					});
				}else {
					f();
				}
			});
		}
			
		$(function() {

			sortableTable(".draggable");
			del_row();

			//項目追加
			$('.btns .left a').click(function(){
				var table = $('#table_category');
				var count = 0;
				$(table).find('tr').each(function() {
					count++
				});
				var str = '<tr id="row' + count + '"><td><a href="javascript:;" class="delete_category">削除</a></td><td><input type="text" name="forms[banner][' + count + ']" value="" class="text" /><input type="hidden" name="forms[array_id][' + count + ']" value="" /></td><td><label><input type="radio" name="forms[status][' + count + ']" value="1" checked />公開</label>&nbsp;<label><input type="radio" name="forms[status][' + count + ']" value="0" />非公開</label></td></tr>';
				$(table).append(str);
				// ドラッグできるようにする初期化
				setRadioAndCheckbox();
				sortableTable(".draggable");
				del_row();
			});
			
			//空の項目を全て削除
			$('.btns .right a').click(function(){
				$('#table_category tbody input[type=text]').each(function(){
					if(!$(this).val()){
						$(".delete_category",$(this).closest('tr')).click();
					}
				});
			});
		});
	</script>
    
</head>
<body>

{include file='include/header.inc.html'}

<div id="container">
	<aside id="accordion">
    	<div id="aside_inner">
    		{include file='include/menu.inc.html'}
        </div>
    </aside>
    
    <article>
    	<h2><span>&nbsp;</span>Banner</span><p><a href="javascript:;">Open Plugins</a></p></h2>
        <nav>
        	<ul>
            	<li><a href="banner.php"><span>スケジューラ</span></a></li>
            	<li class="active"><a href="banner_config.php"><span>種別マスタ</span></a></li>
			</ul>
        </nav>
        
        <section id="content">
        
        	<h3>種別マスタ</h3>
                {if $phase == 'input'}
                    <p class="message">内容を確認し、更新ボタンをクリックしてください。</p>

                    <form name="fm" action="banner_config.php" method="post" enctype="multipart/form-data">
				
                        <ul class="t_btns">
                            <li class="single refresh"><button type="button" class="chk_update"><em>&nbsp;</em>更新</button></li>
                        </ul>

                
                        <ul class="btns b10">
                        	<li class="btn left c"><a href="javascript:;">項目を追加</a></li>
                        	<li class="btn right c"><a href="javascript:;">空の項目を削除</a></li>
                        </ul>
                
                        <h4><span>&nbsp;</span>項目</h4>
                        
                        {include file='banner/include/config_form.inc.html'}

                            <p class="button">
                                    <button type="button" id="btn_update" class="submit"><span>更新</span></button>
                            </p>
                            <input type="hidden" name="mode" value="" />
                            <input type="hidden" name="do" value="validate_edit_form"/>
                    </form>
                {/if}
				
                {if $phase == 'complete'}
                        <p class="message">{$message}</p>

                        <ul class="result_btn">
                                <li><a href="banner_config.php">設定画面に戻る</a></li>
                        </ul>
                {/if}
				
	        </section>
    </article>
    
</div>

{include file='include/footer.inc.html'}

</body>
</html>